package com.learn.spring.common;

import com.learn.spring.bean.Teacher;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        //创建BeanDefinition
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(Teacher.class);

//        rootBeanDefinition.getPropertyValues().add("name", "Teacher");
        // 注册到容器  beanDefinitonMap
//        registry.registerBeanDefinition("teacher", rootBeanDefinition);


        AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) registry.getBeanDefinition("userService");
        // constructor 注入
        beanDefinition.setAutowireMode(3);

    }
}